/*============================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center (DKFZ)
All rights reserved.

Use of this source code is governed by a 3-clause BSD license that can be
found in the LICENSE file.

============================================================================*/

#include "mitkPlanarFigureWriterFactory.h"

#include "itkCreateObjectFunction.h"
#include "itkVersion.h"

#include <mitkPlanarFigureWriter.h>

namespace mitk
{
  template <class T>
  class CreatePlanarFigureWriter : public itk::CreateObjectFunctionBase
  {
  public:
    /** Standard class typedefs. */
    typedef CreatePlanarFigureWriter Self;
    typedef itk::SmartPointer<Self> Pointer;

    /** Methods from itk:LightObject. */
    itkFactorylessNewMacro(Self) LightObject::Pointer CreateObject() override
    {
      typename T::Pointer p = T::New();
      p->Register();
      return p.GetPointer();
    }

  protected:
    CreatePlanarFigureWriter() {}
    ~CreatePlanarFigureWriter() override {}
  private:
    CreatePlanarFigureWriter(const Self &); // purposely not implemented
    void operator=(const Self &);           // purposely not implemented
  };

  PlanarFigureWriterFactory::PlanarFigureWriterFactory()
  {
    this->RegisterOverride("IOWriter",
                           "PlanarFigureWriter",
                           "PlanarFigure xml Writer",
                           true,
                           mitk::CreatePlanarFigureWriter<mitk::PlanarFigureWriter>::New());
  }

  PlanarFigureWriterFactory::~PlanarFigureWriterFactory() {}
  itk::ObjectFactoryBase::Pointer PlanarFigureWriterFactory::GetInstance()
  {
    static itk::ObjectFactoryBase::Pointer factory(mitk::PlanarFigureWriterFactory::New().GetPointer());
    return factory;
  }

  void PlanarFigureWriterFactory::RegisterOneFactory(void)
  {
    if (GetInstance()->GetReferenceCount() == 1)
    {
      ObjectFactoryBase::RegisterFactory(GetInstance().GetPointer());
    }
  }

  void PlanarFigureWriterFactory::UnRegisterOneFactory(void)
  {
    ObjectFactoryBase::UnRegisterFactory(GetInstance().GetPointer());
  }

  const char *PlanarFigureWriterFactory::GetITKSourceVersion() const { return ITK_SOURCE_VERSION; }
  const char *PlanarFigureWriterFactory::GetDescription() const { return "PlanarFigureWriterFactory"; }
} // end namespace mitk
